package com.aco.party.service.system;

import com.aco.party.dao.custom.TermsDao;
import com.aco.party.model.po.Terms;
import com.aco.party.model.vo.TermsVo;
import com.aco.party.model.vo.common.PageParam;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by flying on 3/10/2016 0010.
 */
@Service
public class TermsService {
    @Resource
    private TermsDao termsDao;

    public List<TermsVo> getByPage(PageParam pageParam) {
        List<TermsVo> list = new ArrayList<>();
        List<Terms> termss = termsDao.getList(pageParam);
        TermsVo vo;
        if (termss != null) {
            for (Terms terms : termss) {
                vo = new TermsVo();
                BeanUtils.copyProperties(terms, vo);
                list.add(vo);
            }
        }
        return list;
    }

    public Integer getTotal() {
        return termsDao.getTotal();
    }

    public void update(Terms terms) {
        termsDao.updateByPrimaryKeySelective(terms);
    }

    public void add(Terms terms) {
        termsDao.insertSelective(terms);
    }

    public void delete(Long id) {
        termsDao.deleteByPrimaryKey(id);
    }

    public Terms getByPrimaryKey(Long id) {
        return termsDao.selectByPrimaryKey(id);
    }

    public Terms getBySlug(String slug) {return termsDao.getBySlug(slug);}
}
